package com.smile.config;

import org.springframework.boot.web.server.WebServerFactoryCustomizer;
import org.springframework.boot.web.servlet.server.ConfigurableServletWebServerFactory;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Lazy;
import org.springframework.messaging.simp.config.MessageBrokerRegistry;
import org.springframework.web.socket.config.annotation.EnableWebSocket;
import org.springframework.web.socket.config.annotation.EnableWebSocketMessageBroker;
import org.springframework.web.socket.config.annotation.StompEndpointRegistry;
import org.springframework.web.socket.config.annotation.WebSocketMessageBrokerConfigurer;

@Configuration
@EnableWebSocketMessageBroker
public class WebSocketConfig implements WebSocketMessageBrokerConfigurer {

    @Override
    public void registerStompEndpoints(StompEndpointRegistry registry) {
        System.out.println("<UNK>websocket<UNK>");
        registry.addEndpoint("/ws") // 统一端点路径
                .setAllowedOriginPatterns("*")
                .withSockJS();     // 启用SockJS支持
    }
//    @Bean
//    public WebServerFactoryCustomizer <ConfigurableServletWebServerFactory> webServerFactoryCustomizer() {
//        return factory -> factory.setPort(8081);
//    }
    @Override
    public void configureMessageBroker(MessageBrokerRegistry registry) {
        registry.enableSimpleBroker("/topic", "/queue"); // 消息代理前缀
        registry.setApplicationDestinationPrefixes("/app"); // 应用前缀
    }

}
